package com.globallogic.oopbasics.competence.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author olena.strelchuk
 */

/**
 * Competency is an adequate characteristic of personality's ability to perform
 * some actions in working activities
 */
public abstract class AbstractCompetency implements
		Comparable<AbstractCompetency> {

	private static final int DOUBLE_FOUR_DIGITS_ROUNDING = 10000;
	private static final double DOUBLE_FOUR_DIGITS_DELTA = 0.0001;
	private int id;
	private String name;
	private double globalValue;
	private List<String> paramList = new ArrayList<String>();

	/**
	 * Constructor for Competency
	 */
	public AbstractCompetency(int id, String name, double globalValue) {
		this.id = id;
		this.name = name;
		this.globalValue = globalValue;
	}

	public void addParam(String paramName) {
		paramList.add(paramName);
	}

	public double getGlobalValue() {
		return globalValue;
	}

	public String getName() {
		return name;
	}

	public int getId() {
		return id;
	}

	public List<String> getParamList() {
		return paramList;
	}

	public void setParamList(List<String> paramList) {
		this.paramList = paramList;
	}

	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof AbstractCompetency)) {
			return false;
		}
		return (((AbstractCompetency) other).name.equals(this.name))
				&& (Math.abs(((AbstractCompetency) other).globalValue
						- this.globalValue) <= DOUBLE_FOUR_DIGITS_DELTA);
	}

	public int hashCode() {
		return (int) (this.globalValue * DOUBLE_FOUR_DIGITS_ROUNDING);
	}

	@Override
	public int compareTo(AbstractCompetency competencyCompared) {
		return (int) Math
				.floor((getGlobalValue() * DOUBLE_FOUR_DIGITS_ROUNDING - competencyCompared
						.getGlobalValue() * DOUBLE_FOUR_DIGITS_ROUNDING));
	}

	public String toString() {
		return (name + " with a Value: " + getGlobalValue());
	}
}
